import math

#initial
departmentNum = [103,63,34]
totalNum = 200

#比例加惯例分配法
def halmiton(seatNum):
    print("use the halmiton method and the number of seat :", seatNum)
    integerPart = []
    decimalPart = []
    for i in range(len(departmentNum)):
        tmp = math.modf(departmentNum[i] / totalNum * seatNum)
        integerPart.append(tmp[1])
        decimalPart.append(tmp[0])

    tempSum = int(sum(integerPart))
    while (tempSum != seatNum):
            maxDecimal = max(decimalPart)
            index = decimalPart.index(maxDecimal)
            integerPart[index] += 1
            decimalPart[index] = 0
            tempSum += 1

    results = list(map(int,integerPart))
    return results

#Q值法
def huntingtonHill(seatNum):
    #按个数初始化为1
    seatList = [1] * len(departmentNum)
    while (sum(seatList) != seatNum):
        tempList = []
        for i in range(len(departmentNum)):
            equl = departmentNum[i]*departmentNum[i] / (seatList[i]*(seatList[i]+1))
            tempList.append(equl)

        equlMax = max(tempList)
        index = tempList.index(equlMax)
        seatList[index] += 1

    return seatList

# departmentDict = {'A': 103,'B' : 63,'C' : 34}
#
# def dHondt(departmentDict,seatList):
#     seatDict = {'A': 0,'B' : 0,'C' : 0}
#     tempSeat = 0
#     a = 1
#     b = 1
#     c = 1
#     while (tempSeat != seatList):
#         departmentDict['A'] / a

print("the number of department :" ,departmentNum)
print("when the seats are 21.")
print("using halmiton method",halmiton(21))
print("using huntingtonHill method",huntingtonHill(21))

print("when the seats are 31.")
print("using halmiton method",halmiton(31))
print("using huntingtonHill method",huntingtonHill(31))